import PlugMessage from "@/components/PlugMessage";
import {createApp} from 'vue'

const message = {}
//声明变量存放构造器
let $vm
message.install = function (app) {
    if(!$vm){
        // 1、实例化并绑定组件
        const Message = createApp(PlugMessage);
        $vm = Message.mount(document.createElement("div"));
        document.body.appendChild($vm.$el)
    }
    $vm.isShow = false;
    let message = {
        show(msg='操作成功！',type="success"){
            $vm.isShow = true;
            $vm.msg = msg;
            $vm.type = type;
            setTimeout(() => {
                this.hide()
            },1000)
        },
        hide(){
            $vm.isShow = false;
        }
    }
    if(!app.message){
        app.$message = message
    }
    app.config.globalProperties.$message = app.$message;
}
export default message;
